home *** CD-ROM | disk | FTP | other *** search
/ Gigantic Games 2 / Gigantic Games 2.iso / pc / _w_ / wanderer / src / fall.c < prev    next >
C/C++ Source or Header  |  1994-12-23  |  8KB  |  306 lines

  1. #include "wand_head.h"
  2.  
  3. extern void draw_symbol();
  4. extern int debug_disp;
  5. extern char screen[NOOFROWS][ROWLEN+1];
  6.  
  7. int check(mx,my,x,y,dx,dy,sx,sy,howdead)
  8. /* check for any falling caused by something moving out of x,y along
  9.    vector dx,dy. All the others are constant and should really have
  10.    been global...                             */
  11. int x,y,sx,sy,dx,dy, *mx, *my;
  12. char howdead[25];
  13. {
  14. int ret=0;
  15. ret+=fall(mx,my,x,y,sx,sy,howdead);
  16. ret+=fall(mx,my,x-dx,y-dy,sx,sy,howdead);
  17. ret+=fall(mx,my,x-dy,y-dx,sx,sy,howdead);
  18. ret+=fall(mx,my,x+dy,y+dx,sx,sy,howdead);
  19. ret+=fall(mx,my,x-dx-dy,y-dy-dx,sx,sy,howdead);
  20. ret+=fall(mx,my,x-dx+dy,y-dy+dx,sx,sy,howdead);
  21. return ret;
  22. }
  23.  
  24. int fall(mx,my,x,y,sx,sy,howdead)  /* recursive function for falling */
  25.                    /* boulders and arrows */
  26. int  x,y,sx,sy, *mx, *my;
  27. char howdead[25];
  28. {
  29. int nx = x,nxu = x,nyl = y,nyr = y,retval = 0, makesound = 0;
  30. if ((y>(NOOFROWS-1))||(y<0)||(x<0)||(x>(ROWLEN-1)))
  31.     return(0);
  32. if((screen[y][x] != 'O') && (screen[y][x] != ' ') && (screen[y][x] != 'M') &&
  33.    (screen[y][x] !='\\') && (screen[y][x] != '/') && (screen[y][x] != '@') &&
  34.    (screen[y][x] != '^'))
  35.     return(0);
  36. if(screen[y][x] == 'O')
  37.     {
  38.     if((screen[y][x-1] == ' ') && (screen[y-1][x-1] == ' '))
  39.         nx--;
  40.     else
  41.     {
  42.         if((screen[y][x+1] == ' ') && (screen[y-1][x+1] == ' '))
  43.             nx++;
  44.     else
  45.         nx = -1;
  46.     }
  47.     if((screen[y][x-1] == ' ') && (screen[y+1][x-1] == ' '))
  48.         nxu--;
  49.     else
  50.     {
  51.         if((screen[y][x+1] == ' ') && (screen[y+1][x+1] == ' '))
  52.             nxu++;
  53.     else
  54.         nxu = -1;
  55.     }
  56.     if((screen[y-1][x] == ' ') && (screen[y-1][x+1] == ' '))
  57.         nyr--;
  58.     else
  59.     {
  60.         if((screen[y+1][x] == ' ') && (screen[y+1][x+1] == ' '))
  61.             nyr++;
  62.     else
  63.         nyr = -1;
  64.     }
  65.     if((screen[y-1][x] == ' ') && (screen[y-1][x-1] == ' '))
  66.         nyl--;
  67.     else
  68.     {
  69.         if((screen[y+1][x] == ' ') && (screen[y+1][x-1] == ' '))
  70.             nyl++;
  71.     else
  72.         nyl = -1;
  73.     }
  74.     }
  75. if(screen[y][x] == '\\')
  76.     {
  77.     if(screen[y-1][++nx] != ' ')
  78.     nx = -1;
  79.     if(screen[y+1][--nxu] != ' ')
  80.         nxu = -1;
  81.     if(screen[--nyr][x+1] != ' ')
  82.         nyr = -1;
  83.     if(screen[++nyl][x-1] != ' ')
  84.         nyl = -1;
  85.     }
  86. if(screen[y][x] == '/')
  87.     {
  88.     if(screen[y-1][--nx] != ' ')
  89.     nx = -1;
  90.     if(screen[y+1][++nxu] != ' ')
  91.         nxu = -1;
  92.     if(screen[++nyr][x+1] != ' ')
  93.     nyr = -1;
  94.     if(screen[--nyl][x-1] != ' ')
  95.     nyl = -1;
  96.     }
  97. if((screen[y][nx] != ' ') && (screen[y][nx] != 'M'))
  98.     nx = -1;
  99. if((screen[y-1][x] == 'O') && (nx >= 0) && (y > 0) &&
  100.    (screen[y][nx] != '^')) /* boulder falls ? */
  101.     {
  102.     screen[y-1][x] = ' ';
  103.     if(screen[y][nx] == '@')
  104.         {
  105.     makesound = 1;
  106.         strcpy(howdead,"a falling boulder");
  107.         retval=1;
  108.         }
  109.     if(screen[y][nx] == 'M')
  110.         {
  111.     makesound = 1;
  112.         *mx = *my = -2;
  113.     screen[y][nx] = ' ';
  114.         }
  115.     screen[y][nx] = 'O';
  116.     if(!debug_disp)
  117.     {
  118.         if((y<(sy+5)) && (y>(sy-3)) && (x>(sx-6)) && (x<(sx+6)))
  119.             draw_symbol((x-sx+5)*3,(y-sy+2)*2,' ');
  120.         if((y<(sy+4)) && (y>(sy-4)) && (nx>(sx-6)) && (nx<(sx+6)))
  121.             draw_symbol((nx-sx+5)*3,(y-sy+3)*2,'O');
  122.     }
  123.     else
  124.     {
  125.     move(y,x+1);
  126.     draw_map_symbol(' ');
  127.     move(y+1,nx+1);
  128.     draw_map_symbol('O');
  129.     }
  130.     refresh();
  131.  
  132. #ifdef BOULDER_SOUND
  133.     {
  134.     int w,e,s,sw,se;
  135.  
  136.     /* try to predict if boulder has stopped falling */
  137.     /* so we know when to trigger the sound */
  138.     w = screen[y][nx-1];
  139.     e = screen[y][nx+1];
  140.     s = screen[y+1][nx];
  141.     sw = screen[y+1][nx-1];
  142.     se = screen[y+1][nx+1];
  143.  
  144.     if (s != ' ' && s != '/' && s != '\\' && s != 'O')
  145.         makesound = 1;
  146.     else if (s == 'O')
  147.          {
  148.         if (w != ' ' && e != ' ')
  149.             makesound = 1;
  150.         else if (w != ' ' && e == ' ' && se != ' ')
  151.             makesound = 1;
  152.         else if (w == ' ' && e != ' ' && sw != ' ')
  153.             makesound = 1;
  154.         else if (w == ' ' && sw != ' ' && e == ' ' && se != ' ')
  155.             makesound = 1;
  156.          }
  157.     else if (s == '/' && sw != ' ')
  158.         makesound = 1;
  159.     else if (s == '\\' && se != ' ')
  160.         makesound = 1;
  161.  
  162.     if (makesound) playSound(BOULDER_SOUND);
  163.     }
  164. #endif
  165.  
  166.     retval+=fall(mx,my,nx ,y+1,sx,sy,howdead);
  167.     retval+=check(mx,my,x,y-1,0,1,sx,sy,howdead);
  168.     if(screen[y+1][nx] == '@')
  169.         {
  170.     if (!makesound) playSound(BOULDER_SOUND);
  171.         strcpy(howdead,"a falling boulder");
  172.         return(1);
  173.         }
  174.     if(screen[y+1][nx] == 'M')
  175.         {
  176.     if (!makesound) playSound(BOULDER_SOUND);
  177.         *mx = *my = -2;
  178.     screen[y+1][nx] = ' ';
  179.         }
  180.     }
  181. if((screen[nyr][x] != '^')&&(screen[nyr][x] != ' ')&&(screen[nyr][x] != 'M'))
  182.     nyr = -1;
  183. if((screen[y][x+1] == '<')&&(nyr>=0)&&(x+1<ROWLEN)) /* arrow moves ( < ) ? */
  184.     {
  185.     screen[y][x+1] = ' ';
  186.     if(screen[nyr][x] == '@')
  187.         {
  188.     playSound(ARROW_SOUND);
  189.         strcpy(howdead,"a speeding arrow");
  190.         retval = 1;
  191.         }
  192.     if(screen[nyr][x] == 'M')
  193.         {
  194.     playSound(ARROW_SOUND);
  195.         *mx = *my = -2;
  196.     screen[nyr][x] = ' ';
  197.         }
  198.     screen[nyr][x] = '<';
  199.     if(!debug_disp)
  200.     {
  201.         if((y<(sy+4)) && (y>(sy-4)) && (x<(sx+5)) && (x>(sx-7)))
  202.             draw_symbol((x-sx+6)*3,(y-sy+3)*2,' ');
  203.         if((nyr<(sy+4)) && (nyr>(sy-4)) && (x<(sx+6)) && (x>(sx-6)))
  204.             draw_symbol((x-sx+5)*3,(nyr-sy+3)*2,'<');
  205.     }
  206.     else
  207.     {
  208.     move(y+1,x+2);
  209.     draw_map_symbol(' ');
  210.     move(nyr+1,x+1);
  211.     draw_map_symbol('<');
  212.     }
  213.     refresh();
  214.     retval+=fall(mx,my,x-1,nyr,sx,sy,howdead);
  215.     retval+=check(mx,my,x+1,y,-1,0,sx,sy,howdead);
  216.     if(screen[nyr][x-1] == '@')
  217.         {
  218.     playSound(ARROW_SOUND);
  219.         strcpy(howdead,"a speeding arrow");
  220.         return(1);
  221.         }
  222.     if(screen[nyr][x-1] == 'M')
  223.         {
  224.     playSound(ARROW_SOUND);
  225.         *mx = *my = -2;
  226.     screen[nyr][x-1] = ' ';
  227.         }
  228.     }
  229. if((screen[nyl][x] != ' ')&&(screen[nyl][x] != '^')&&(screen[nyl][x] != 'M'))
  230.     nyl = -1;
  231. if((screen[y][x-1] == '>')&&(nyl>=0)&&(x>0))       /* arrow moves ( > ) ? */
  232.     {
  233.     screen[y][x-1] = ' ';
  234.     if(screen[nyl][x] == '@')
  235.         {
  236.     playSound(ARROW_SOUND);
  237.         strcpy(howdead,"a speeding arrow");
  238.         retval = 1;
  239.         }
  240.     if(screen[nyl][x] == 'M')
  241.         {
  242.     playSound(ARROW_SOUND);
  243.         *mx = *my = -2;
  244.     screen[nyl][x] = ' ';
  245.         }
  246.     screen[nyl][x] = '>';
  247.     if(!debug_disp)
  248.     {
  249.         if((y<(sy+4)) && (y>(sy-4)) && (x<(sx+7)) && (x>(sx-5)))
  250.             draw_symbol((x-sx+4)*3,(y-sy+3)*2,' ');
  251.         if((nyl<(sy+4)) && (nyl>(sy-4)) && (x<(sx+6)) && (x>(sx-6)))
  252.             draw_symbol((x-sx+5)*3,(nyl-sy+3)*2,'>');
  253.     }
  254.     else
  255.     {
  256.     move(y+1,x);
  257.     draw_map_symbol(' ');
  258.     move(nyl+1,x+1);
  259.     draw_map_symbol('>');
  260.     }
  261.     refresh();
  262.     retval+=fall(mx,my,x+1,nyl,sx,sy,howdead);
  263.     retval+=check(mx,my,x-1,y,1,0,sx,sy,howdead);
  264.     if(screen[nyl][x+1] == '@')
  265.         {
  266.     playSound(ARROW_SOUND);
  267.         strcpy(howdead,"a speeding arrow");
  268.         return(1);
  269.         }
  270.     if(screen[nyl][x+1] == 'M')
  271.         {
  272.     playSound(ARROW_SOUND);
  273.         *mx = *my = -2;
  274.     screen[nyl][x+1] = ' ';
  275.         }
  276.     }
  277. if(screen[y][nxu] != ' ')
  278.     nxu = -1;
  279. if((screen[y+1][x] == '^') && (nxu >= 0) && (y < NOOFROWS) &&
  280.    (screen[y][x] != '^')) /* balloon rises? */
  281.     {
  282.     screen[y+1][x] = ' ';
  283.     screen[y][nxu] = '^';
  284.     if(!debug_disp)
  285.     {
  286.         if((y<(sy+3)) && (y>(sy-5)) && (x>(sx-6)) && (x<(sx+6)))
  287.             draw_symbol((x-sx+5)*3,(y-sy+4)*2,' ');
  288.         if((y<(sy+4)) && (y>(sy-4)) && (nxu>(sx-6)) && (nxu<(sx+6)))
  289.             draw_symbol((nxu-sx+5)*3,(y-sy+3)*2,'^');
  290.     }
  291.     else
  292.     {
  293.     move(y+2,x+1);
  294.     draw_map_symbol(' ');
  295.     move(y+1,nxu+1);
  296.     draw_map_symbol('^');
  297.     }
  298.     refresh();
  299.     retval+=fall(mx,my,nxu ,y-1,sx,sy,howdead);
  300.     retval+=check(mx,my,x,y+1,0,-1,sx,sy,howdead);
  301.     }
  302. if(retval>0)
  303.     return(1);
  304. return(0);
  305. }
  306.